import request from "@/utils/request";
import type {
  AttrList,
  AttrListParams,
  AttrItem,
  AttrValueList,
} from "./model/attrModel";

const enum Api {
  getAttrInfoListApi = "/admin/product/attrInfoList",
  updateOrAddAttrValueListApi = "/admin/product/saveAttrInfo",
  delAttrApi = "/admin/product/deleteAttr",
  getAttrValueListApi = "/admin/product/getAttrValueList",
}

/**
 * 获取商品基础属性接口
 * @param category1Id category2Id category3Id
 * @returns AttrValueList
 */
export const GetAttrInfoListApi = ({
  category1Id,
  category2Id,
  category3Id,
}: AttrListParams) => {
  return request.get<number, AttrList>(
    Api.getAttrInfoListApi + `/${category1Id}/${category2Id}/${category3Id}`
  );
};

/**
 * 更改或添加属性值
 * @param data AttrItem
 * @returns null
 */
export const UpdateOrAddAttrValueListApi = (data: AttrItem) => {
  return request.post<number, null>(Api.updateOrAddAttrValueListApi, data);
};

/**
 * 删除属性
 * @param attrId 属性id
 * @returns null
 */
export const DelAttrApi = (attrId: number) => {
  return request.delete<number, null>(Api.delAttrApi + `/${attrId}`);
};

/**
 * 获取属性值列表
 * @param attrId 属性id
 * @returns attrValueList
 */
export const GetAttrValueListApi = (attrId: number) => {
  return request.get<number, AttrValueList>(
    Api.getAttrValueListApi + `/${attrId}`
  );
};
